<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>城乡综合信息管理系统登录</title>

    <%--移动设备优先--%>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>

    <%--公共css样式--%>
    <link rel="icon" href="/static/images/favicon.ico">

    <%--引入类库--%>
    <link rel="stylesheet" type="text/css" href="/static/webjars/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css"/>
    <script type="application/javascript" src="/static/js/jquery.min.js"></script>

</head>
<body class="layui-layout-body">

    <%--登陆框--%>
    <div class="layadmin-user-login">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>后台管理</h2>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"></label>
                    <input type="text" name="account" placeholder="账号" class="layui-input" autocomplete="off" />
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
                    <input type="password" name="password" placeholder="密码" class="layui-input" autocomplete="off" />
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"></label>
                            <input type="text" name="vercode" lay-verify="required" placeholder="验证码" class="layui-input" autocomplete="off"/>
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img id="img"  src="/api/auth/getImage" onclick="javascript:changeImg()"  class="layadmin-user-login-codeimg">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid btn-submit">登 入</button>
                </div>
            </div>
        </div>
    </div>


</body>
    <script type="application/javascript" src="/static/webjars/layui/layui.js"></script>
    <script>
        <%--JavaScript代码区域--%>
        layui.use(['element','layer'], function(){
            var element = layui.element
                , layer = layui.layer;

            <%--表单提交--%>
            $(".btn-submit").click(function(){
                var params = {
                    account:$("input[name=account]").val(),
                    password:$("input[name=password]").val(),
                    code:$("input[name=vercode]").val()
                };
                if(params.account === "" || params.password === "" || params.code === ""){
                    layer.alert("请完善登陆信息");
                    return;
                }else{
                    <%--验证码确认--%>
                    $.post(
                        "/api/auth/validImage",{
                            code:params.code
                        },function(res){
                            <%--先修改验证码--%>
                            changeImg();
                            if(res != 200){
                                layer.alert("验证码错误！");
                            }else{
                                $.post("/ajax/auth/login",params,function(r){
                                    if(r.code !=0){
                                        layer.alert("用户名或者密码错误！");
                                        console.log(r);
                                    }else{

                                        console.log(r);
                                        layer.alert("登陆成功！",{
                                            icon:1,
                                            closeBtn:1
                                        },function(){
                                            location.href="/auth/index";
                                        });
                                    }
                                });
                            }
                        }
                    );
                }
            });
        });

        <%--验证码刷新--%>
        function changeImg(){
            document.getElementById("img").src = "/api/auth/getImage?date=" + new Date();
        }


    </script>
</html>


